/*
 * 竞拍活动商品列表
 * @author 狮子
 * @time 2018/9/29
 * @since 1.0.0
 * */
// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import { Row, Col, Card, Button, Tabs, Form, Popconfirm, Modal, Tooltip} from 'antd'
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'

// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
//引用listPage
import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'
// 当前组件样式
import styles from './walletStatisticsStyle.less'
import { Grid, QueryCondition } from 'widget/Grid/index'
import { AdvanceSearch } from 'widget/CollapsiblePanels/index'
import { chunk } from 'lodash'

/**
 * description 路由视图及事件处理
 * dispatch 分发到models中的effects对应事件名
 * model 用于获取models中state定义的数据
 * form 表单对象
 */

const routeView = function ({dispatch, model, form}) {
  // 表单的子函数
  const {resetFields, getFieldDecorator, validateFields, setFieldsValue} = form
  // 取出model对象，命名空间
  const {modelObj, namespace} = model
  let {loading, btnLoading, modalObj, currentItem, queryList, tableData, pageConfig,result} = modelObj
  // modelObj.xxx获取model中状态机的值
  console.log('modelObj', modelObj);
  // console.log("result:"+result)
  // 点击处理事件
  const clickHandler = (e) => {
    // 分发到model文件中effects的xxx方法
    dispatch({
      type: `${namespace}/xxx`,
      payload: {}
    })
  }

  const columns = [
    {title: '用户钱包统计', dataIndex: 'data', key: 'data',
    render: (a, item, index, d, e, f) => {
      var aStyle = {
        color:'#0877FD'
      }
      var aStyle2 = {
        color:'#333'
      }
      return (
        <span>
          <a style={item.data!=0?{ color:'#0877FD'}:{ color:"#333"}}  onClick={() => routerGo()}>{item.data}</a>
        </span>
      )
    } },
   
  ]
  // 表格模板配置
  const gridProps = {
    nameSpace: namespace,
    data: {
      // columns: [].concat(columns, generateAction()),
      columns: columns,
      pageConfig, tableData
    },
    // pageChange: (pageNo, pageSize) => {
    //   console.log(pageNo, pageSize)
    //   dispatch({ type: `${namespace}/pageChange`, payload: {pageNo, pageSize } });
    // },
    // scroll: {x: 800},
    // loading


  }

  // 表格操作区域
  // function generateAction () {
  //   return {
  //     title: '操作',
  //     key: 'operation',
  //     fixed: 'right',
  //     width: 200,
  //     render: (data, record, index) => {
  //       return (
  //         <span>
  //           <a onClick={() => updateModal({item: record, index})}>详情</a>{<span className="ant-divider"/>}
  //         </span>
  //       )
  //     }
  //   }
  // }

  // 详情页跳转
  function routerGo (query) {
    let startTime = queryList[0].value[0];
    let endTime = queryList[0].value[1];
    if(startTime === undefined && endTime ===undefined){
      return;
    }
    let querys = {
      ...query,
      startTime:startTime,
      endTime:endTime
    }
    hashHistory.push({
      pathname: '/home/threadAdmin/walletList',
      query:querys
    })
  }

  //修改状态
  const changeState = (payload) => {
    dispatch({
      type: `${namespace}/updateStore`,
      payload: {...payload}
    })
  }
  //修改状态
  const inputChange = (payload) => {
    let {key, value} = payload
    dispatch({
      type: `${namespace}/inputChange`,
      payload: {
        ...payload
      }
    })
  }
  //查询
  const onSearch = (payload) => {
    dispatch({
      type: `${namespace}/search`,
      payload: payload
    })
  }

  return (
    <div className={cx('pageLayout')}>
      <div className="public_listMain">
        <AdvanceSearch
          footer={
            <span>
                <Button type="primary" htmlType="submit" onClick={() => onSearch()} loading={loading}>搜索</Button>
                <Button onClick={() => dispatch({ type: `${namespace}/queryReset` })}>重置</Button>
              </span>
          }
        >
          <QueryCondition
            data={queryList}
            inputChange={(key, value) => dispatch({type: `${namespace}/inputChange`, payload: {key, value}})}
          />
        </AdvanceSearch>
        {/* 表格区域 */}

        {/* <div>{result}</div> */}

        <div className="boxShadow">
          {/* 添加用户 */}
          <Grid {...gridProps} />
        </div>
      </div>
    </div>
  )
}

// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(routeView))

